package com.sangmo.fts.training.repo;

import com.sangmo.boot.framework.plugin.dataview.spi.jpa.IJpaDataViewRepo;
import com.sangmo.fts.training.model.Team;
import com.sangmo.fts.training.model.Teammate;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TeammateRepo extends IJpaDataViewRepo<Teammate> {

    List<Teammate> findByTeamId(Long teamId);

    Teammate findByTeamIdAndUserId(Long teamId, Long userId);

    @Query("select count(tm.id) from Teammate tm where EXISTS(select 1 from Team t where t.id = tm.teamId and t.examinationId = :examinationId)")
    int countByExaminationId(@Param("examinationId") Long examinationId);
}
